<template>
  <div>
    <el-button @click="show">更新</el-button>

    <!-- {{ hos1 }} -->
    <el-table :data="this.hos1.list" style="width: 100%">
      <el-table-column align="center" prop="id" label="编号" width="100"></el-table-column>
      <el-table-column align="center" prop="name" label="医院名称" width="180"></el-table-column>
      <el-table-column align="center" prop="introduce" label="医院简介" width="180"></el-table-column>
      <el-table-column align="center" prop="province" label="医院地址">
        <!-- 插槽 -->
        <!-- <template v-slot="scope">
          <div v-html="scope.row.content"></div>
        </template>-->
      </el-table-column>

      <el-table-column align="center" prop="longitude" label="经度" width="180"></el-table-column>
      <el-table-column prop="latitude" label="纬度" width="180"></el-table-column>

      <!-- 时间方法1 -->
      <!-- <el-table-column prop="publishTime" label="发布时间">
        <template v-slot="scope">
      <!-- |管道符  将左侧的变量做为参数传递够右侧的函数-->
      <!-- <div>{{ scope.row.publishTime | dateFMT }}</div>
        </template>
      </el-table-column>-->
      -->
      <!-- <el-table-column label="操作">
        <template v-slot="scope">
          <el-button @click="delete_hospital(scope.row.id)">删除</el-button>
          <el-button @click="edit_hospital(scope.row)">修改</el-button>
        </template>
      </el-table-column>-->
    </el-table>
    <el-pagination
      background
      layout="prev, pager, next"
      :page-size="hos1.list.pageSize"
      :current-page="hos1.list.page"
      :total="hos1.total"
      @current-change="changepage"
    ></el-pagination>

    <!-- 模态框 -->
    <div class="atc">
      <!-- <img alt="Vue logo" src="../assets/logo.png">
      <HelloWorld msg="Welcome to Your Vue.js App"/>-->
      <!-- <el-button @click="show">登录</el-button> -->
      <el-dialog :title="title" :visible.sync="dialog_hospital">
        <el-form :model="form_hospital">
          {{ form_hospital }}
          <el-form-item label="名称" :label-width="formLabelWidth_hospital">
            <el-input v-model="form_hospital.name"></el-input>
          </el-form-item>
          <el-form-item label="简介" :label-width="formLabelWidth_hospital">
            <el-input v-model="form_hospital.introduce"></el-input>
          </el-form-item>
          <el-form-item label="详细地址" :label-width="formLabelWidth_hospital">
            <el-input v-model="form_hospital.address"></el-input>
          </el-form-item>

          <el-form-item label="地址" :label-width="formLabelWidth_hospital">
            <!-- <el-input v-model="form_hospital.province" ></el-input> -->
            <el-cascader
              v-model="form_hospital.tag"
              :options="pca"
              :props="{ expandTrigger: 'hover', label:'name' ,value:'name'}"
              @change="handleChange"
            ></el-cascader>
          </el-form-item>
          <!-- 
          <el-form-item label="经度" :label-width="formLabelWidth_hospital">
            <el-input v-model="form_hospital.longitude" ></el-input>
          </el-form-item>-->
          <!-- <el-form-item label="纬度" :label-width="formLabelWidth_hospital">
            <el-input v-model="form_hospital.latitude" disabled></el-input>
          </el-form-item>-->
          <!-- <el-form-item label="纬度" :label-width="formLabelWidth_hospital">
            <el-input v-model="form_hospital.latitude" ></el-input>
          </el-form-item>-->
          <el-form-item label="选择经纬度" :label-width="formLabelWidth_hospital">
            <el-button @click="showmap">打开地图</el-button>
          </el-form-item>
          <!-- {{options}} -->
        </el-form>
        <div slot="footer" class="dialog-footer">
          <!-- <el-button @click="delete_hospital">取 消</el-button> -->
          <el-button type="primary" @click="saveOrupdate">保存</el-button>
        </div>
      </el-dialog>
      <el-dialog title="选择地点" :visible.sync="dialog_map">
        <div id="containermap"></div>

        <div slot="footer" class="dialog-footer">
          <!-- <el-button @click="delete_hospital">取 消</el-button> -->
          <el-button type="primary" @click="okmap">确定</el-button>
        </div>
      </el-dialog>
    </div>
  </div>
</template>

<script scoped>
import { mapActions, mapState } from "vuex";
import pca from "../../assets/404_images/pca.json";

export default {
  computed: {
    ...mapState("hos", ["hos1"])
  },
  data() {
    return {
      pca,
      obj: {
        page: 1,
        pageSize: 10
      },
      vshow: false,
      newobj: {},
      title: "新增医院",
      dialog_hospital: false,
      form_hospital: {},
      formLabelWidth_hospital: "120px",

      dialog_map: false
    };
  },
  watch: {
    obj: {
      handler: function() {
        this.findhos(this.obj);
      },
      deep: true
    }
  },
  created() {
    this.findhos(this.obj);
  },
  methods: {
    ...mapActions("hos", ["findhos", "savehos"]),
    changepage(page) {
      this.obj.page = page;
    },

    saveOrupdate() {
      if (this.form_hospital.tag) {
        this.form_hospital.province = this.form_hospital.tag[0];
        this.form_hospital.city = this.form_hospital.tag[1];
        this.form_hospital.area = this.form_hospital.tag[2];
        delete this.form_hospital.tag;
      }
      console.log(this.form_hospital);
      // this.savehos(this.form_hospital).then(res => {
      //   console.log(res);
      // });
      this.dialog_hospital = false;
    },
    show() {
      this.dialog_hospital = true;
    },
    handleChange() {},
    showmap() {
      (dialog_map = true),
        setTimeout(() => {
          this.initmap();
        }, 1000);
      initmap();
    },
    initmap() {
      var map = new AMap.Map("containermap", {
        resizeEnable: true
      });
    },
    okmap() {
      dialog_map = false;
      this.form_hospital.longitude = this.form_hospital.tag[1];
      this.form_hospital.latitude = this.form_hospital.tag[2];
    }
  }
};
</script>


